package com.blog.util;

import com.blog.model.ErrorEnum;

import java.io.Serializable;

/**
 * @Description: 响应工具类
 * @Author: 刘会俊
 * @Date: 2018-12-21 15:17
 */
public class ResponseUtil<T> implements Serializable {



    private int code;

    private String message;

    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    private ResponseUtil() {
    }

    /**
     *@description: 成功响应
     *@author: 刘会俊
     *@params: []
     *@return: com.blog.util.ResponseUtil
     */
    public static ResponseUtil success(){
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.setCode(ErrorEnum.SUCCESS.getCode());
        responseUtil.setMessage(ErrorEnum.SUCCESS.getMessage());
        return responseUtil;
    }

    /**
     *@description: 失败响应
     *@author: 刘会俊
     *@params: []
     *@return: com.blog.util.ResponseUtil
     */
    public static ResponseUtil fail(){
        ResponseUtil responseUtil = new ResponseUtil();
        responseUtil.setCode(ErrorEnum.SUCCESS.getCode());
        responseUtil.setMessage(ErrorEnum.SUCCESS.getMessage());
        return responseUtil;
    }

}
